<template>
	<view :class="['qn-page-' + theme]">
		<block v-for="(item, index) in temData" :key="index">
			<!-- 搜索组件 -->
			<SearchInput v-if="item.comName === 'SearchC'" :modelData="item.modelData"></SearchInput>
			<!-- 轮播图 -->
			<USwiper v-if="item.comName === 'ImgSwiper'" :modelData="item.modelData"></USwiper>
			<!-- 公告 -->
			<Notice v-if="item.comName === 'Notice'" :modelData="item.modelData" :noticeData="item.data"></Notice>
			<!-- 导航栏 -->
			<UNavigation v-if="item.comName === 'NavBar'" :modelData="item.modelData"></UNavigation>
			<!-- 辅助空白 -->
			<Blank v-if="item.comName === 'Blank'" :modelData="item.modelData"></Blank>
			<!-- 辅助线 -->
			<Line v-if="item.comName === 'LineF'" :modelData="item.modelData"></Line>
			<!-- 魔方图片组 -->
			<MagicImg v-if="item.comName === 'MagicImg'" :modelData="item.modelData"></MagicImg>
			<!-- 图片组 -->
			<ImagesGroup v-if="item.comName === 'ImgGroup'" :modelData="item.modelData"></ImagesGroup>
			<!-- 秒杀 -->
			<LimitedSeckill v-if="item.comName === 'LimitedSeckill'" :modelData="item.modelData" :limitedData="item.data"></LimitedSeckill>
			<!-- 优惠券组 -->
			<CouponGroup v-if="item.comName === 'CouponGroup'" :modelData="item.modelData"></CouponGroup>
			<!-- 标题栏 -->
			<Title v-if="item.comName === 'Title'" :modelData="item.modelData"></Title>
			<!-- 商品组 -->
			<GoodsGroup v-if="item.comName === 'GoodsGroup'" :modelData="item.modelData" :goodsList="item.data"></GoodsGroup>
			<!-- 微信客服 -->
			<wxContact v-if="item.comName === 'wxService'" :modelData="item.modelData"></wxContact>
			<!-- 浮动按钮 -->
			<FloatBtn v-if="item.comName === 'FloatBth'" :modelData="item.modelData"></FloatBtn>
		</block>
		<!-- 底部tabbar -->
		<Tabbar v-model="current"></Tabbar>
	</view>
</template>

<script>
import Line from './components/Line';
import Blank from './components/Blank';
import SearchInput from './components/SearchInput';
import USwiper from './components/USwiper';
import UNavigation from './components/UNavigation';
import ImagesGroup from './components/ImagesGroup';
import CouponGroup from './components/CouponGroup';
import Title from './components/Title';
import LimitedSeckill from './components/LimitedSeckill';
import GoodsGroup from './components/GoodsGroup';
import MagicImg from './components/MagicImg';
import Notice from './components/Notice';
import wxContact from './components/wxContact';
import FloatBtn from './components/FloatBtn';
export default {
	components: {
		SearchInput,
		USwiper,
		UNavigation,
		ImagesGroup,
		CouponGroup,
		LimitedSeckill,
		GoodsGroup,
		Title,
		Blank,
		Line,
		MagicImg,
		Notice,
		wxContact,
		FloatBtn
	},
	data() {
		return {
			current: 0,
			temData: []
		};
	},
	onLoad() {
		uni.setNavigationBarTitle({
			title: this.$store.state.basicSet.shop || '千鸟云商'
		});
		this.getHome();
		// this.getBasicField();
		// #ifdef MP-WEIXIN
		// 小程序的原生菜单中显示分享按钮
		uni.showShareMenu({
			withShareTicket: false,
			menus: ['shareAppMessage', 'shareTimeline']
		});
		// #endif
	},
	onPullDownRefresh() {
		this.getHome();
		this.getBasicField();
	},
	// #ifdef MP-WEIXIN
	// 分享到朋友圈
	onShareTimeline(obj) {},
	// 收藏小程序
	onAddToFavorites() {},
	// #endif
	methods: {
		getHome() {
			this.$u.api.getHome().then(({ data }) => {
				uni.stopPullDownRefresh();
				this.temData = data;
			});
		},
		// 获取配置项
		getBasicField() {
			/*
			startUpPage 启动页
			shop 商城名称
			themeStyle 商城主题
			classSetting 分类模版
			recommend 推荐搜索
			startDeliveryPrice 起送价
			goodsPrice 商品价格是否允许游客查看，5 是，4 否
			stockDisplay 库存展示 4 不显示库存 5 显示有/无货 6显示库存数量
			isSalesNum 销量展示 4 不显示销量 5 显示销量
			*/

			this.$u.api
				.getBasicField({
					field: ['startUpPage', 'shop', 'themeStyle', 'classSetting', 'recommend','startDeliveryPrice','goodsPrice','stockDisplay','isSalesNum']
				})
				.then(({ data }) => {
					uni.setNavigationBarTitle({
						title: data.shop || '千鸟云商'
					});
					this.$store.commit('commit_basicSet', data);
				});
		}
	}
};
</script>
